package com.kly.domain.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 用户角色枚举
 *
 * @author admin
 * @date 2025/3/2
 */
@Getter
public enum SpaceRoleEnum {
    VIEWER("浏览者", "viewer"),
    EDITOR("编辑者", "editor"),
    ADMIN("管理员", "admin");


    private final String text;

    private final String value;

    SpaceRoleEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据value获取枚举
     *
     * @param value
     * @return
     */
    public static SpaceRoleEnum getEnumByValue(String value) {
        if (StrUtil.isBlank(value)) {
            return null;
        }
        Map<String, SpaceRoleEnum> map = Arrays.stream(SpaceRoleEnum.values())
                .collect(Collectors.toMap(SpaceRoleEnum::getValue, userRoleEnum -> userRoleEnum));
        return map.getOrDefault(value, null);
    }
}
